Conditions | 5 |
Paths | 5 |
Total Lines | 56 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** global: appSettings */ |
||
18 | ipcRenderer.on('bwa:fileinput.confirmation', function(event, filePath = null, isDragDrop = false) { |
||
19 | const { |
||
20 | misc, |
||
21 | lookup |
||
22 | } = appSettings; |
||
23 | var bwaFileStats; // File stats, size, last changed, etc |
||
24 | |||
25 | //console.log(filePath); |
||
26 | if (filePath === undefined || filePath == '' || filePath === null) { |
||
27 | //console.log(filePath); |
||
28 | $('#bwaFileinputloading').addClass('is-hidden'); |
||
29 | $('#bwaEntry').removeClass('is-hidden'); |
||
30 | } else { |
||
31 | $('#bwaFileSpanInfo').text('Loading file stats...'); |
||
32 | if (isDragDrop === true) { |
||
33 | $('#bwaEntry').addClass('is-hidden'); |
||
34 | $('#bwaFileinputloading').removeClass('is-hidden'); |
||
35 | bwaFileStats = fs.statSync(filePath); |
||
36 | bwaFileStats['filename'] = filePath.replace(/^.*[\\\/]/, ''); |
||
37 | bwaFileStats['humansize'] = conversions.byteToHumanFileSize(bwaFileStats['size'], misc.usestandardsize); |
||
38 | $('#bwaFileSpanInfo').text('Loading file contents...'); |
||
39 | bwaFileContents = Papa.parse(fs.readFileSync(filePath).toString(), { header: true }); |
||
40 | } else { |
||
41 | bwaFileStats = fs.statSync(filePath[0]); |
||
42 | bwaFileStats['filename'] = filePath[0].replace(/^.*[\\\/]/, ''); |
||
43 | bwaFileStats['humansize'] = conversions.byteToHumanFileSize(bwaFileStats['size'], misc.usestandardsize); |
||
44 | $('#bwaFileSpanInfo').text('Loading file contents...'); |
||
45 | bwaFileContents = Papa.parse(fs.readFileSync(filePath[0]).toString(), { header: true }); |
||
46 | } |
||
47 | //console.log(bwaFileContents.data[0]); |
||
48 | $('#bwaFileSpanInfo').text('Getting line count...'); |
||
49 | bwaFileStats['linecount'] = bwaFileContents.data.length; |
||
50 | bwaFileStats['filepreview'] = JSON.stringify(bwaFileContents.data[0], null, "\t").substring(0, 50); |
||
51 | bwaFileStats['errors'] = JSON.stringify(bwaFileContents.errors).slice(1,-1); |
||
52 | //console.log(bwaFileContents.data); |
||
53 | |||
54 | //console.log(readLines(filePath[0])); |
||
55 | //console.log(bwFileStats['filepreview']); |
||
56 | |||
57 | //console.log(lineCount(bwFileContents)); |
||
58 | $('#bwaFileinputloading').addClass('is-hidden'); |
||
59 | $('#bwaFileinputconfirm').removeClass('is-hidden'); |
||
60 | |||
61 | // stats |
||
62 | $('#bwaFileTdFilename').text(bwaFileStats['filename']); |
||
63 | $('#bwaFileTdLastmodified').text(conversions.getDate(bwaFileStats['mtime'])); |
||
64 | $('#bwaFileTdLastaccessed').text(conversions.getDate(bwaFileStats['atime'])); |
||
65 | $('#bwaFileTdFilesize').text(bwaFileStats['humansize'] + ' ({0} record(s))'.format(bwaFileStats['linecount'])); |
||
66 | $('#bwaFileTdFilepreview').text(bwaFileStats['filepreview'] + '...'); |
||
67 | $('#bwaFileTextareaErrors').text(bwaFileStats['errors'] || "No errors"); |
||
68 | //$('#bwTableMaxEstimate').text(bwFileStats['maxestimate']); |
||
69 | //console.log('cont:'+ bwFileContents); |
||
70 | |||
71 | //console.log(bwFileStats['linecount']); |
||
72 | } |
||
73 | }); |
||
74 | |||
148 |